﻿using System.Windows;
using System.Windows.Input;
using MSUS.Kinect.PowerPointController.ViewModels;
using Microsoft.Research.Kinect.Nui;
using Application = Microsoft.Office.Interop.PowerPoint.Application;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

namespace MSUS.Kinect.PowerPointController
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
	    public PowerPoint.Application PowerPointApplication { get; private set; }

		public MainWindow()
		{
			InitializeComponent();
		}

        public MainWindow(Application powerPointApplication) : base()
        {
            PowerPointApplication = powerPointApplication;

            InitializeComponent();

            Device devices = new Device();
            if (devices.Count == 0) throw new NoActiveKinectException();
        }


		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			MainViewModel model = this.DataContext as MainViewModel;
		    if (model == null) return;
		    model.PowerPointApplication = PowerPointApplication;
            model.Begin(MainCanvas, FullTrackingImage, HandTrackingImage);
		}


		private void Window_KeyDown(object sender, KeyEventArgs e)
		{
			MainViewModel model = this.DataContext as MainViewModel;
			if (model != null)
				model.OnKeyDown(e.Key);
		}

		private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			MainViewModel model = this.DataContext as MainViewModel;
			if (model != null)
				model.Dispose();
		}
	}
}
